﻿using Haidou.Wpf.Util.Settings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Haidou.Wpf.UI.ViewModel
{
	/// <summary>
	/// 更新可用
	/// </summary>
	public class UpdateAvailable
	{

		/// <summary>
		/// 是否需要更新
		/// </summary>
		public static bool IsUpdate { get; set; } = false;

		public bool IsFromQx5ai { get; set; } = true;

		/// <summary>
		/// 更新二进制标识失败。
		///更新必须手动完成。
		/// </summary>
		public bool MustDownloadManually { get; set; } = false;

		public bool HasDownloadLink => !string.IsNullOrWhiteSpace(InstallerDownloadUrl);

		public Version Version { get; set; }

		public string Description { get; set; }

		public bool IsDownloading { get; set; }


		public string InstallerPath { get; set; }

		public string InstallerName { get; set; }


		/// <summary>
		/// 安装包下载地址
		/// </summary>
		public string InstallerDownloadUrl { get; set; }

		public long InstallerSize { get; set; }

		/// <summary>
		/// 便携包路径
		/// </summary>
		public string PortablePath { get; set; }
		/// <summary>
		/// 便携包
		/// </summary>
		public string PortableName { get; set; }
		/// <summary>
		/// 便携包
		/// </summary>
		public string PortableDownloadUrl { get; set; }

		/// <summary>
		/// 
		/// </summary>
		public long PortableSize { get; set; }

#if FULL_MULTI_MSIX
    public string ActivePath
    {
        get => InstallerPath;
        set => InstallerPath = value;
    }

    public string ActiveName => InstallerName;
    public string ActiveDownloadUrl => InstallerDownloadUrl;
    public long ActiveSize => InstallerSize;
#else
		/// <summary>
		/// 活动路径
		/// </summary>
		public string ActivePath
		{
			get => UserSettings.All.PortableUpdate ? PortablePath : InstallerPath;
			set
			{
				if (UserSettings.All.PortableUpdate)
				{
					PortablePath = value;
				}
				else
				{
					InstallerPath = value;
				}
			}
		}

		public string ActiveName => UserSettings.All.PortableUpdate ? PortableName : InstallerName;
		public string ActiveDownloadUrl => UserSettings.All.PortableUpdate ? PortableDownloadUrl : InstallerDownloadUrl;
		public long ActiveSize => UserSettings.All.PortableUpdate ? PortableSize : InstallerSize;
#endif

		public TaskCompletionSource<bool> TaskCompletionSource { get; set; }



		public string title { get; set; }

		public string type { get; set; }


	}
}
